﻿using IBLL;
using IBLL.Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace WebHouseTypeAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HouseNumController : ControllerBase
    {
        public HouseNumController(IHouseNumBLL bLL)
        {
            BLL = bLL;
        }

        public IHouseNumBLL BLL { get; }

        /// <summary>
        /// 房号添加信息
        /// </summary>
        /// <param name="houseNum">房号实体对象</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public async Task<int> AddAsync(HouseNum houseNum)
        {
            try
            {
                return await BLL.AddAsync(houseNum);
            }
            catch (Exception)
            {

                throw;
            }
            
        }
        /// <summary>
        /// 根据编号id删除一条信息
        /// </summary>
        /// <param name="Id">编号id</param>
        /// <returns>返回受影响的行数</returns>
        [HttpDelete]
        public async Task<int> DeleteAsync(int Id)
        {
            try
            {
                return await BLL.DeleteAsync(Id);
            }
            catch (Exception)
            {

                throw;
            }
           
        }
        /// <summary>
        /// 分页查询信息
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="size">页容量</param>
        /// <param name="name">房型名称模糊查询</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public GetPageData GetHousePage(int index, int size, string? name)
        {
            try
            {
                return BLL.GetHousePage(index, size, name);
            }
            catch (Exception)
            {

                throw;
            }
          

        }

        /// <summary>
        /// 根据编号id查询一条信息
        /// </summary>
        /// <param name="Id">编号id</param>
        /// <returns></returns>
        [HttpGet]
        public HouseNum GetValue(int Id)
        {
            try
            {
                return BLL.GetValue(Id);
            }
            catch (Exception)
            {

                throw;
            }
          
        }
        /// <summary>
        /// 逻辑删除 根据编号id，修改其是否删除状态
        /// </summary>
        /// <param name="Id">编号id</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> LogicDelete(int Id)
        {
            try
            {
                return await BLL.LogicDelete(Id);
            }
            catch (Exception)
            {

                throw;
            }
          
        }
        /// <summary>
        /// 修改房号信息
        /// </summary>
        /// <param name="houseNum">房号实体对象</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateAsync(HouseNum houseNum)
        {
            try
            {
                return await BLL.UpdateAsync(houseNum);
            }
            catch (Exception)
            {

                throw;
            }
         
        }


    }
}
